<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<button id="btn">按钮</button>
<script>

(function (window){
    var a = 10;
    btn.onclick = function (){
        console.log(a);
    }
})(window)

</script>
<script>
a = 20;
</script>
</body>
</html>